import _ from "lodash"

const defaultOptions = {
    title: null,
    content: null,
    okText: "确 定",
    icon: null,
    okType: 'primary',
    closable: true,
    cancelText: "取 消",
    width: 416,
    centered: true,
    onOk: () => {},
    onCancel: () => {}
}

const user = {
  state: {
    visible: false,
    options: _.cloneDeep(defaultOptions)
  },
  mutations: {
    SET_VISIBLE: (state, visible) => {
        state.visible = visible;
    },
    SET_OPTIONS: (state, options) => {
        state.options = options
    }
  },
  actions: {
    modalConfirm({ commit, dispatch }, options = {}) {
        commit("SET_VISIBLE", true)
        commit("SET_OPTIONS", Object.assign(_.cloneDeep(defaultOptions), options))

        return {
            destroy: () => {
                dispatch('modalCancel')
            }
        }
    },
    modalCancel({ commit }){
        commit("SET_VISIBLE", false)
        commit("SET_OPTIONS", _.cloneDeep(defaultOptions))
    }
  },
};

export default user;
